package com.abo.yaas.domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

import com.abo.yaas.i18n.FieldTranslation;

@Entity
@XmlRootElement
@Table(name = "TBL_User")
@SuppressWarnings("serial")
public class User extends YaasPojo {
    @FieldTranslation(tuid = "LOAD_IMAGE")
    private byte[] userPic;

    @FieldTranslation(tuid = "FIRST_NAME")
    private String firstName = "";

    @FieldTranslation(tuid = "LAST_NAME")
    private String lastName = "";

    @FieldTranslation(tuid = "EMAIL")
    private String email = "";

    @FieldTranslation(tuid = "USER_NAME")
    private String login = "";

    @FieldTranslation(tuid = "PASSWORD")
    private String password = "";

    @FieldTranslation(tuid = "DUPLICATE_PASSWORD")
    private String duplicatePassword = "";

    private Boolean isAdmin = false;

    private String passwordHash = "";

    public User() {
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null || !(obj instanceof User)) {
            return false;
        }

        if (obj == this) {
            return true;
        }

        if (getId() == null) {
            return super.equals(obj);
        }

        return getId().equals(((User) obj).getId());
    }

    @Transient
    public String getDuplicatePassword() {
        return duplicatePassword;
    }

    @Column(name = "Email")
    public String getEmail() {
        return email;
    }

    @Column(name = "FirstName")
    public String getFirstName() {
        return firstName;
    }

    @Transient
    public String getFullName() {
        return getFirstName() + " " + getLastName();
    }

    @Column(name = "IsAdmin")
    public Boolean getIsAdmin() {
        return isAdmin;
    }

    @Column(name = "LastName")
    public String getLastName() {
        return lastName;
    }

    @Column(name = "UserName")
    public String getLogin() {
        return login;
    }

    @Transient
    public String getPassword() {
        return password;
    }

    @Column(name = "Password")
    @XmlTransient
    public String getPasswordHash() {
        return passwordHash;
    }

    @Column(name = "UserPic")
    public byte[] getUserPic() {
        return userPic;
    }

    @Override
    public int hashCode() {
        int result = firstName.hashCode();
        result += 31 * lastName.hashCode();
        result += 31 * email.hashCode();
        result += 31 * login.hashCode();
        return result;
    }

    public void setDuplicatePassword(String duplicatePassword) {
        this.duplicatePassword = duplicatePassword;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public void setIsAdmin(Boolean isAdmin) {
        this.isAdmin = isAdmin;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void setPasswordHash(String passwordHash) {
        this.passwordHash = passwordHash;
    }

    public void setUserPic(byte[] userpic) {
        this.userPic = userpic;
    }
}
